// CDQ
// https://soj.turingedu.cn/problem/61101/
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 1e5;
const int maxn = 5 + 1e5;

int n;
int x[maxn], y[maxn];
int decoder[maxn], dsiz;
void init_decoder() {
    dsiz = n;
    rf(i, dsiz) decoder[i] = y[i];
    sort(decoder + 1, decoder + 1 + dsiz);
    dsiz = unique(decoder + 1, decoder + 1 + dsiz) - decoder - 1;
    rf(i, n) y[i] = lower_bound(decoder + 1, decoder + 1 + dsiz, y[i]) - decoder;
}

struct BIT {
    int val[max_size];
    void update(int i, int x) {
        while (i <= dsiz) val[i] = max(val[i], x), i += i & -i;
    }
    void clear(int i, int x) {
        while (i <= dsiz) val[i] = x, i += i & -i;
    }

    int ask(int i) {
        int ret = 0;
        while (i > 0) ret = max(ret, val[i]), i -= i & -i;
        return ret;
    }
} bt;

int dp[maxn];
int id[maxn];
bool cmp(int i, int j) { return x[i] != x[j] ? x[i] < x[j] : i > j; } // 严格小于，相等时第一分量大的优先

void cdq(int l, int r) {
    if (l == r) return;
    int mid = l + r >> 1;
    cdq(l, mid);

    for (int i = l; i <= r; ++i) id[i] = i;
    sort(id + l, id + r + 1, cmp);
    for (int j = l; j <= r; ++j) {
        int i = id[j];
        if (i <= mid) // 左边维护数据
            bt.update(y[i], dp[i]);
        else // 右边统计
            dp[i] = max(dp[i], bt.ask(y[i] - 1) + 1);
    }

    // 清空树状数组
    for (int j = l; j <= r; ++j) {
        int i = id[j];
        if (i <= mid) bt.clear(y[i], 0);
    }
    cdq(mid + 1, r);
}

int ans[maxn];

int main() {
    n = rad();
    rf(i, n) x[i] = rad(), y[i] = rad();
    init_decoder();
    rf(i, n) dp[i] = 1;
    cdq(1, n);
    printf("%d ", *max_element(dp + 1, dp + 1 + n));
    // rf(i, n) printf("%d ", dp[i]);
    // puts("");
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}